package com.syscom.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.syscom.common.entity.SysRoleMenu;
import com.syscom.common.mapper.SysRoleMenuMapper;
import com.syscom.common.utils.result.AjaxResult;
import com.syscom.common.utils.result.ResultTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wjz
 * @date 2021-01-14
 */
@Slf4j
@Service
public class SysRoleMenuService {

    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper;

    public AjaxResult querySysRoleMenuById(Long objectId) {

        QueryWrapper<SysRoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("menu_json").eq("role_id", objectId);
        queryWrapper.orderByAsc("object_id");
        return ResultTool.success(sysRoleMenuMapper.selectOne(queryWrapper));
    }

    public AjaxResult addSysRoleMenu(SysRoleMenu sysRoleMenu) {

        return ResultTool.success(sysRoleMenuMapper.insert(sysRoleMenu));
    }

    public AjaxResult updateSysRoleMenu(Long roleId, SysRoleMenu sysRoleMenu) {

        return ResultTool.success(sysRoleMenuMapper.update(sysRoleMenu, new UpdateWrapper<SysRoleMenu>().eq("role_id", roleId)));
    }

    public AjaxResult deleteSysRoleMenu(Long objectId) {

        return ResultTool.success(sysRoleMenuMapper.deleteById(objectId));
    }
}

